<template>
<div>
  <el-table
      :data="tableData"
      stripe
      style="width: 60%">
    <el-table-column
        prop="date"
        label="考试日期"
        width="180">
    </el-table-column>
    <el-table-column
        prop="name"
        label="考试名字"
        width="180">
    </el-table-column>
    <el-table-column
        prop="passLine"
        label="及格线"
        width="120">
    </el-table-column>
    <el-table-column
        prop="grade"
        label="考试成绩"
        width="120">
    </el-table-column>
    <el-table-column label="成绩评级">
      <template slot-scope="scope">
        <el-button
            size="mini" type="danger"
            v-if="scope.row.grade<scope.row.passLine">不及格</el-button>
        <el-button
            size="mini" type="success"
            v-if="scope.row.grade>scope.row.passLine">及格</el-button>
      </template>

    </el-table-column>
    <el-table-column label="操作">
      <template slot-scope="scope">
        <el-button
            size="mini"
            @click="handleEdit(scope.$index, scope.row)">查看答案</el-button>

      </template>
    </el-table-column>
  </el-table>
  <el-pagination
      @size-change="handleSizeChange"
      v-bind:child-msg="pageparm"
      @current-change="handleCurrentChange"
      :current-page="pageparm.currentPage"
      :page-sizes="[3, 5, 10, 15]"
      :page-size="pageparm.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="pageparm.total" style="margin-left:200px;margin-top:16px">
  </el-pagination>
</div>
</template>

<script>
import {Utils} from "@/utils/Util";

export default {
  created() {
    this.showGrade()
  },
  methods:{
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.form.limit =val
      this.form.page = 1
      //this.findAll(this.formInline)
      this.showGrade()
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.form.page = val
      //this.findAll(this.formInline)
      this.showGrade()
    },
    handleEdit(index, row) {

        this.showAnswer(row.paperId)
    },
    showAnswer(id){
      this.$axios.post("http://localhost:8080/student/showAnswer/"+id).then(
          res=>{
            console.log(res.data.data)
            Utils.putStorage("rowSubjectInfo",res.data.data)
            this.$router.push("/detail")
          }
      ).catch()
    },
    showGrade(){
      this.$axios.post("http://localhost:8080/student/showGradeByUserId",this.form).
      then(res=>{
        this.pageparm.currentPage = this.form.page
        this.pageparm.pageSize = this.form.limit
        this.pageparm.total = res.data.data.total
        let data = res.data.data.list
        console.log(data)
        let tableData=[]
        for(let i in data){

          tableData.push(
              {
                date: data[i].examQuizTime,
                name:data[i].paperName,
                grade:data[i].grade,
                paperId:data[i].paperId,
                passLine:data[i].passLine
              }
          )
        }
        this.tableData =tableData
      }).catch()
    }

  },
  name: "examResults",
  data(){

    return{
      form:{
        page:1,
        limit:5,
        //模拟用户数据 现在默认是1
        userId:1,
      },
      pageparm:{
        currentPage:1,
        pageSize:5,
        total:0,
      },

      tableData: [
      //     {
      //   date: '2016-05-02',
      //   name: '一年级语文期末考试',
      //   grade: '87'
      // },
      ]


    }

  }
}
</script>

<style scoped>

</style>